﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using pay.DAL;

/// <summary>
///Web_videoDAL 的摘要说明
/// </summary>
public class Web_videoDAL
{
	        /// <summary>
        /// 得到最近的视频对象
        /// </summary>
        /// <returns></returns>
        public Web_video GetNeareastVideo()
        {
            SqlConnection con = null;
            SqlDataReader reader = null;
            try
            {
                Tools tool = new Tools();
                con = new SqlConnection(DBConn.Con_emweb_new);
                reader = Emoney.DataAccess.SqlHelper.ExecuteReader(con, CommandType.StoredProcedure, "web_video_nearest", tool.GetSqlParameters());
                Web_video m = null;
                if (reader.Read())
                {
                    m = new Web_video();
                    m.V_id = Tools.GetInt(reader["v_id"]);
                    m.Classid = Tools.GetInt(reader["classid"]);
                    m.V_title = Tools.GetString(reader["v_title"]);
                    m.V_remark = Tools.GetString(reader["v_remark"]);
                    m.V_power = Tools.GetString(reader["v_power"]);
                    m.V_url = Tools.GetString(reader["v_url"]);
                    m.V_urlnum = Tools.GetInt(reader["v_urlnum"]);
                    m.Onclick = Tools.GetInt(reader["onclick"]);
                    m.V_order = Tools.GetInt(reader["v_order"]);
                    m.V_star = Tools.GetInt(reader["v_star"]);
                    m.Istop = Tools.GetString(reader["istop"]);
                    m.Isgood = Tools.GetString(reader["isgood"]);
                    m.Ishidden = Tools.GetString(reader["ishidden"]);
                    m.Setup_user = Tools.GetString(reader["setup_user"]);
                    m.Setup_date = Tools.GetDateTime(reader["setup_date"]);
                }
                return m;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                try
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                }
                catch
                {
                }
            }


        }

        /// <summary>
        /// 根据查询参数得到视频集合
        /// </summary>
        /// <param name="q">查询参数</param>
        /// <returns>视频集合</returns>
        public DataTable GetVieoByParam( VideoQuery q)
        {
            SqlConnection con = null;
            SqlDataReader reader = null;
            try
            {
                Tools tool = new Tools();
                tool.AddSqlParameter("@sign", SqlDbType.Int, q.Sign);
                tool.AddSqlParameter("@v_id", SqlDbType.Int, q.V_id);
                tool.AddSqlParameter("@classid", SqlDbType.Int, q.Classid);
                tool.AddSqlParameter("@topnum", SqlDbType.Int, q.Topnum);
                con = new SqlConnection(DBConn.Con_emweb_new);
                DataSet ds = Emoney.DataAccess.SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "web_video_select_w", tool.GetSqlParameters());
                return ds.Tables[0];
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (con != null)
                {
                    con.Close();
                }
            }
        }
}